<?php

namespace Biz\module\Classes\adm;

use Biz\model\trade\Order as mOrder;
use Biz\model\trade\OrderGoods as mOrderGoods;
use Biz\service\trade\Logistics as sLogistics;
use Doraemon\service\User as sUser;
use Biz\tools\OrderNo as toolOrderNo;
use Biz\module\Classes\OrderGoods as clsOrderGoods;

class OrderMessage
{
    private $orderNo;
    private $skuId;

    public function __construct($orderNo, $skuId)
    {
        $this->orderNo = $orderNo;
        $this->skuId = $skuId;
    }

    public function getInfo()
    {
        $result = [];

        if (toolOrderNo::isParentNo($this->orderNo)) {
            throw new \Exception('父订单不支持查看', 0);
        }

        $orderGoods = $this->getOrderGoods();

        $orderGoods['cover_img'] = $orderGoods['cover_img_thumb_url'];
        $orderGoods['cover_img_big'] = $orderGoods['cover_img_url'];
        $result['goods_info'] = $orderGoods;
        $result['nick'] = sUser::getUser($orderGoods['uid'])['nick'];
        $result['order_no'] = $this->orderNo;

        $orderInfo = mOrder::getOrderInfo($this->orderNo);
        $result['order_info'] = $orderInfo;
        //物流信息
        $result['delivery_tracking'] = (array)sLogistics::trackingmore($this->orderNo);

        $result['ship_status'] =clsOrderGoods::checkSkuIsDeliveryIncludePartShip($this->orderNo,$this->skuId,$orderInfo);

        return $result;
    }

    private function getOrderGoods()
    {
        $result = mOrderGoods::get(['uid', 'shop_id', 'title', 'cover_img', 'sku_desc'], ['order_no' => $this->orderNo, 'sku_id' => $this->skuId]);

        if (empty($result)) {
            return [];
        }
        mOrderGoods::formatInfo($result);
        return $result;
    }
}